package com.zerui.manager.web;

import com.zerui.cola.dto.MultiResponse;
import com.zerui.cola.dto.PageResponse;
import com.zerui.cola.dto.Response;
import com.zerui.cola.dto.SingleResponse;
import com.zerui.devicemanager.provider.DeviceDubboService;
import com.zerui.devicemanager.provider.dto.ProductDetailDTO;
import com.zerui.devicemanager.provider.dto.ProductTreeDTO;
import com.zerui.manager.web.cmd.DeviceTouchQryCmd;
import com.zerui.manager.web.enums.DeviceFromEnum;
import com.zerui.manager.web.vo.DeviceTouchPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Validated
@Api(value = "门禁设备落地", tags = "门禁设备落地（从IoT和ICC落地到本地表）")
@RestController
@RequestMapping("/api/v1/touch")
public class DeviceTouchController {
    @DubboReference
    private DeviceDubboService deviceDubboService;
    @Resource
    private DeviceTouchService deviceTouchService;
    @Resource
    private DeviceTouchSyncService deviceTouchSyncService;

    @ApiOperation(value = "门禁设备信息源", tags = "门禁设备信息源（IoT/ICC）")
    @GetMapping("/from")
    public Response from() {
        return SingleResponse.of(DeviceFromEnum.getOptions());
    }

    @ApiOperation(value = "同步落地门禁设备信息", tags = "从IoT和ICC落地到本地表")
    @PostMapping("/sync")
    public Response sync(@RequestBody @NotEmpty(message = "请选择你要落地的信息源") List<Integer> froms) {
        return deviceTouchSyncService.syncData(froms);
    }

    @PostMapping("/product")
    public Response product() {
        MultiResponse<ProductTreeDTO> productRepo = deviceDubboService.getProductList();
        return SingleResponse.of(productRepo.getData());
    }

    @ApiOperation(value = "设备分页信息", tags = "设备分页信息")
    @PostMapping("/pageDeviceList")
    public PageResponse<DeviceTouchPageVO> pageDeviceList(@RequestBody @Validated DeviceTouchQryCmd qryCmd) {
        return deviceTouchService.getPageDeviceList(qryCmd);
    }
}
